使用 CSS 創建波浪動畫效果,可以通過 @keyframes
和 transform
屬性來實現波浪形的運動
<div class="wave-container">
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
</div>
body {
margin: 0;
overflow: hidden; /* 防止滾動條顯示 */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: white;
}
.wave-container {
position: relative;
width: 100%;
height: 800px;
}
wave-container
的相對定位,讓內部的波浪能夠絕對定位.wave {
position: absolute;
width: 200vw;
height: 200vw;
background-color: #ff191b;
opacity: 0.4;
top: -75vw;
left: 50%;
margin-left: -100vw;
margin-top: -100vw;
border-radius: 43%;
animation: wave-animation 10s infinite linear;
}
.wave:nth-child(1) {
animation: wave-animation 20s infinite linear;
opacity: 0.1;
background-color: #777;
}
.wave:nth-child(2) {
animation: wave-animation 25s infinite linear;
opacity: 0.1;
background-color: #777;
}
@keyframes wave-animation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}